package com.pig4cloud.pig.demo.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pig.demo.dto.Result;
import com.pig4cloud.pig.demo.dto.SmartAppGoodsDto;
import com.pig4cloud.pig.demo.entity.SmartAppGoods;
import com.pig4cloud.pig.demo.service.SmartAppGoodsService;
import com.pig4cloud.pig.demo.mapper.SmartAppGoodsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
@Slf4j
public class SmartAppGoodsServiceImpl extends ServiceImpl<SmartAppGoodsMapper, SmartAppGoods>
    implements SmartAppGoodsService {


	@Override
	public Result<List<SmartAppGoodsDto>> getList() {

		List<SmartAppGoods> list = this.list();
		List<SmartAppGoodsDto> smartAppGoodsDtos = BeanUtil.copyToList(list, SmartAppGoodsDto.class);
		return new Result(200, "success", smartAppGoodsDtos);
	}

	@Override
	public Result<SmartAppGoodsDto> getById(Long id) {


		SmartAppGoods byId = super.getById(id);
		SmartAppGoodsDto smartAppGoodsDto = BeanUtil.copyProperties(byId, SmartAppGoodsDto.class);
		return new Result(200, "success", smartAppGoodsDto);
	}

	@Override
	public Result delete(Long id) {

		this.removeById(id);
		return new Result(200,"success", null);
	}

	@Override
	public Result add(SmartAppGoodsDto goodsDto) {

		SmartAppGoods smartAppGoods = BeanUtil.copyProperties(goodsDto, SmartAppGoods.class);
		this.save(smartAppGoods);
		return new Result(200,"success", null);
	}

	@Override
	public Result update(SmartAppGoodsDto goodsDto) {
		SmartAppGoods smartAppGoods = BeanUtil.copyProperties(goodsDto, SmartAppGoods.class);
		this.updateById(smartAppGoods);
		return new Result(200,"success", null);
	}
}




